﻿package mortal.game.view.hardware
{
    import com.gengine.core.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import com.gengine.manager.*;
    import com.mui.controls.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.game.mvc.*;
    import mortal.game.view.task.*;
    import mortal.mvc.core.*;

    public class AccelerateController extends Controller
    {
        private var _fpsTxtBtn:GButton;
        private var _secTime:SecTimer;
        private var _count:int = 0;
        private var _frameRate:int = 0;
        private var FpsLimit:int = 35;
        private var _testCount:int = 60;

        public function AccelerateController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            EventUtil.addSelfEvent(EventName.NavbarButtonUIRowInited, this.initHd, true);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.checkShowIcon);
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.checkShowIcon);
            return;
        }// end function

        private function initHd(param1:Object) : void
        {
            this._secTime = new SecTimer(1);
            this._secTime.addListener(TimerType.ENTERFRAME, this.onFreshHd);
            return;
        }// end function

        private function onFreshHd(param1:SecTimer) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this._count + 1;
            _loc_2._count = _loc_3;
            this._frameRate = this._frameRate + this.getFrameRate();
            if (this._count >= this._testCount)
            {
                if (this._frameRate / this._count < this.FpsLimit)
                {
                    this.showBtnTxt(true);
                }
                else
                {
                    this.showBtnTxt(false);
                }
                this._count = 0;
                this._frameRate = 0;
            }
            return;
        }// end function

        private function getFrameRate() : int
        {
            var _loc_1:* = FPS.instance.fpsNum;
            if (_loc_1 > 0)
            {
                return _loc_1;
            }
            return 30;
        }// end function

        private function showBtnTxt(param1:Boolean) : void
        {
            if (this.fpsTxtBtn)
            {
                this.fpsTxtBtn.visible = param1;
            }
            return;
        }// end function

        public function get fpsTxtBtn() : GButton
        {
            return (GameController.task.view as TaskTrackModuleNew).kaCkTxt;
        }// end function

        private function onShowTip(event:MouseEvent) : void
        {
            OtherBrowserTipWindow.instance.show();
            return;
        }// end function

        private function checkShowIcon(param1 = null) : void
        {
            var _loc_2:* = BrowerManager.instance.getBrowserType();
            if (cache.role.entityInfo.level >= 4 && cache.role.entityInfo.level < 40 && (FrameUtil.driveInfo.indexOf("unavailable") != -1 || FrameUtil.driveInfo.indexOf("oldDriver") != -1 || FrameUtil.driveInfo.indexOf("OpenGL") != -1) && _loc_2 == "Sogou")
            {
                if (HardwareIcon.hasInstance())
                {
                    HardwareIcon.instance.show();
                }
                else
                {
                    HardwareIcon.instance.show();
                    HardwareIcon.instance.playEffect();
                    HardwareIcon.instance.tweenPosition();
                }
            }
            else if (HardwareIcon.hasInstance())
            {
                HardwareIcon.instance.stopEffect();
                HardwareIcon.instance.hide();
            }
            return;
        }// end function

    }
}
